package dgut.party.business.mockdata;

import dgut.party.business.dao.MenuRepository;
import dgut.party.business.dao.rbac.AuthorityRepository;
import dgut.party.business.entity.base.Menu;

import java.util.ArrayList;
import java.util.List;

public class MockMenusBean {
  public static void initMenus(MenuRepository menuRepo, AuthorityRepository authRepo) {

    Menu sys = Menu.builder().name("系统板块").icon("settings").auth(authRepo.findByName("menu_sys")).subMenus(sysMenus(authRepo)).build();
    Menu org = Menu.builder().name("组织管理").icon("dashboard").auth(authRepo.findByName("menu_org")).subMenus(orgMenus(authRepo)).build();
    Menu pub = Menu.builder().name("公示板块").icon("web").auth(authRepo.findByName("menu_pub")).subMenus(pubMenus(authRepo)).build();
    pub.getSubMenus().stream().forEach((sub) -> {
      sub.setSupMenu(pub);
    });
    org.getSubMenus().stream().forEach((sub) -> {
      sub.setSupMenu(org);
    });
    sys.getSubMenus().stream().forEach((sub) -> {
      sub.setSupMenu(sys);
    });

    List<Menu> seconds = new ArrayList<>();
    seconds.add(pub);
    seconds.add(org);
    seconds.add(sys);
    Menu root = Menu.builder().name("menu_root").auth(authRepo.findByName("menu_root")).subMenus(seconds).build();
    root.getSubMenus().stream().forEach((sub) -> {
      sub.setSupMenu(root);
    });
    menuRepo.save(root);

  }

  public static List<Menu> orgMenus(AuthorityRepository authRepo) {
    List<Menu> menus = new ArrayList<>();
//    menus.add(Menu.builder().name("组织资料").auth(authRepo.findByName("menu_org_info")).build());
    menus.add(Menu.builder().name("组织结构").auth(authRepo.findByName("menu_org_orgTree")).build());
//    menus.add(Menu.builder().name("组织成员").auth(authRepo.findByName("menu_org_member")).build());
//    menus.add(Menu.builder().name("组织管理").auth(authRepo.findByName("menu_org_mg")).build());
    return menus;
  }

  public static List<Menu> pubMenus(AuthorityRepository authRepo) {
    List<Menu> menus = new ArrayList<>();
    menus.add(Menu.builder().name("所有公示").auth(authRepo.findByName("menu_pub_page")).build());
//    menus.add(Menu.builder().name("公示管理").auth(authRepo.findByName("menu_pub_mg_page")).build());
    menus.add(Menu.builder().name("创建公告").auth(authRepo.findByName("menu_pub_mg_create")).build());
    return menus;
  }

  public static List<Menu> sysMenus(AuthorityRepository authRepo) {
    List<Menu> menus = new ArrayList<>();
    menus.add(Menu.builder().name("个人信息").auth(authRepo.findByName("menu_sys_user_info")).build());
    menus.add(Menu.builder().name("权限管理").auth(authRepo.findByName("menu_sys_mg_role_auth_map")).build());
    menus.add(Menu.builder().name("用户管理").auth(authRepo.findByName("menu_sys_mg_account")).build());
    return menus;
  }
}
